﻿
package extremefx.unitTest {
	import flash.text.TextField;	

	/**
	 * @author Marcelo Volmaro
	 */
	public class Assert {
		private static var _tf:TextField;
		public static function setOutput(pTF:TextField = null):void {
			_tf = pTF;
		}
		
		public static function areEquals(expected:Object, actual:Object, message:String = "" ):void
		{
			if ( expected != actual )
			   failWithUserMessage( message, "expected:<" + expected + "> but was:<" + actual + ">" );
		}
	
		public static function areStrictlyEquals(expected:Object, actual:Object, message:String = "" ):void
		{
			if ( expected !== actual )
			   failWithUserMessage( message, "expected:<" + expected + "> but was:<" + actual + ">" );
		}
	
		public static function isTrue(condition:Boolean, message:String = "" ):void
		{
			if ( !condition )
			   failWithUserMessage( message, "expected true but was false" );
		}
	
		public static function isFalse( condition:Boolean, message:String = "" ):void
		{
			if ( condition )
			   failWithUserMessage( message, "expected false but was true" );
		}
	
		public static function isNull(object:Object, message:String = "" ):void
		{
			if ( object == null )
			   failWithUserMessage( message, "object was null: " + object );
		}
	
		public static function isNotNull( object:Object, message:String = ""  ):void
		{
			if ( object != null )
			   failWithUserMessage( message, "object was not null: " + object );
		}

	//------------------------------------------------------------------------------
	
		public static function fail( failMessage:String = ""):void
		{
//			throw new AssertionFailedException( failMessage );
			var e:Error = new Error( failMessage );
			
			if (_tf){
				_tf.appendText(e.getStackTrace());
				
			} else {
				trace (e);
			}
			
		}
	
	//------------------------------------------------------------------------------
	
		private static function failWithUserMessage( userMessage:String, failMessage:String ):void
		{
			if ( userMessage.length > 0 )
				userMessage = userMessage + " - ";
				
			var e:Error =new Error( userMessage + failMessage );
			
			if (_tf){
				_tf.appendText(e.getStackTrace());
				_tf.appendText("\r\n");
				
			} else {
				trace (e);
			}
	
//			throw new AssertionFailedException( userMessage + failMessage );
			
		}
		
	}
}
